package example.chapter12.checkboxlist;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;

import example.chapter12.model.Flower;

public class CheckboxlistTagAction extends ActionSupport{
	
	private List<String> checkedPets;
	private List<String> checkedFruits;
	private List<String> checkedFlowers;
	
	private List<String> listPets;	
	private Map<String,String> mapFruits;	
	private List<Flower> listFlowers;
	
	public String execute() throws Exception{
		//Example1: String List
		listPets = new ArrayList<String>();
		
		listPets.add("dog");
		listPets.add("cat");
		listPets.add("bird");
		
		if(checkedPets != null){
			for(int i = 0; i < checkedPets.size(); i++){
				System.out.println("checkedPets: " + checkedPets.get(i));
			}
		}
		
		//Example2: Map
		mapFruits = new HashMap<String,String>();
		
		mapFruits.put("a", "apple");
		mapFruits.put("g", "grape");
		mapFruits.put("o", "orange");
		
		if(checkedFruits != null){
			for(int i = 0; i < checkedFruits.size(); i++){
				System.out.println("checkedFruits: " + checkedFruits.get(i));
			}
		}
		
		//Example3: Object List
		listFlowers = new ArrayList<Flower>();
		
		listFlowers.add(new Flower("1", "rose"));
		listFlowers.add(new Flower("2", "cosmos"));
		listFlowers.add(new Flower("3", "lily"));
		
		if(checkedFlowers != null){
			for(int i = 0; i < checkedFlowers.size(); i++){
				System.out.println("checkedFlowers: " + checkedFlowers.get(i));
			}
		}
		
		return SUCCESS;
	}

	public List<String> getCheckedPets() {
		return checkedPets;
	}

	public void setCheckedPets(List<String> checkedPets) {
		this.checkedPets = checkedPets;
	}

	public List<String> getCheckedFruits() {
		return checkedFruits;
	}

	public void setCheckedFruits(List<String> checkedFruits) {
		this.checkedFruits = checkedFruits;
	}

	public List<String> getCheckedFlowers() {
		return checkedFlowers;
	}

	public void setCheckedFlowers(List<String> checkedFlowers) {
		this.checkedFlowers = checkedFlowers;
	}

	public List<String> getListPets() {
		return listPets;
	}

	public void setListPets(List<String> listPets) {
		this.listPets = listPets;
	}

	public Map<String, String> getMapFruits() {
		return mapFruits;
	}

	public void setMapFruits(Map<String, String> mapFruits) {
		this.mapFruits = mapFruits;
	}

	public List<Flower> getListFlowers() {
		return listFlowers;
	}

	public void setListFlowers(List<Flower> listFlowers) {
		this.listFlowers = listFlowers;
	}
	
}
